<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /* 
           *****
           ****
           ***
           **
           *
           思路：双重for 循环，外层控制行，内层控制列
           i       num 的最大值
           0           5
           1           4
           2           3
           3           2
           4           1
           
           i + num = 5
           num = 5 - i;
           观察现象 总结规律
       */
        for (let i = 0; i < 5; i++) { //
            let str = '';
            for (let k = 0; k < 5 - i; k++) {
                str = str + '*'
            }
            console.log(str);
        }
        console.log(`----------------1----------------`);
        /*

          *
          **
          ***
          ****
          *****

         i       num 的最大值
         0           1
         1           2
         2           3
         3           4
         4           5

          i = num + 1
          num = i + 1
          */
        for (let i = 0; i < 5; i++) {
            let str = '';
            for (let k = 0; k < i + 1; k++) {
                str = str + '*'
            }
            console.log(str);
        }
        console.log(`----------------2----------------`);


        /*
                       *
                      **
                     ***
                    ****
                   *****
                  
         
                   
                   */

     // 结合上面两个 套第三种
        for (let i = 0; i < 5; i++) {
            let str = '';
            for (let k = 0; k < 4 - i; k++) {// 倒三角的5-i
                str = str + ' ';
            }
            for (let j = 0; j < i + 1; j++) {//再套一个内循环 正三角的i+1
                str = str + '*';
            }
            console.log(str);
        }
        console.log(`----------------3----------------`);
    </script>
</body>

</html>